﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Logging;

namespace StyleMVVM.LanguageExtensions
{
	public static class EventHandlerExtensions
	{
		public static void InvokeSafely<T>(this EventHandler<T> handler, object sender, T args)
		{
			if (handler != null)
			{
				try
				{
					handler(sender, args);
				}
				catch (Exception exp)
				{
					Logger.Error("Exception thrown while invoking event",
					             "StyleMVVM.LanguageExtensions.InvokeSafely " + typeof(T),
					             exp);
				}
			}
		}
	}
}